package ${cfg.basePackage}.module.${cfg.moduleName}.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.Wrapper;
import com.baomidou.mybatisplus.core.conditions.update.Wrapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ${cfg.basePackage}.common.model.SRS;
import ${cfg.basePackage}.module.${cfg.moduleName}.service.${entity}Service;
import puffer.starter.db.dao.Dao;
import puffer.starter.db.entity.Dnt;
import puffer.starter.db.entity.Page;

import java.util.List;
import java.util.Map;

/**
 * ${table.comment!}实现
 */
@Slf4j
@Service
public class ${entity}ServiceImpl implements ${entity}Service {
    @Autowired
    private PfDao dao;

    //新增
    @Override
    public SRS add(${r"Map<String, Object> param"}) {
        param.remove("id");
        long insert = dao.insert("${table.name}", DbEnt.parse(param));
        return SRS.bySuccess(insert);
    }

    //删除
    @Override
    public SRS del(${r"Map<String, Object> param"}) {
        Wrapper${r"<Object>"} wrapper = new Wrapper<>();
        wrapper.eq("id", param.getOrDefault("id", 0));
        long delete = dao.delete("${table.name}", wrapper);
        return SRS.bySuccess(delete);
    }

    //修改
    @Override
    public SRS edit(${r"Map<String, Object> param"}) {
        Wrapper${r"<Object>"} wrapper = new Wrapper<>();
        wrapper.eq("id", param.getOrDefault("id", 0));
        long update = dao.update("${table.name}", wrapper);
        return SRS.bySuccess(update);
    }

    //查询详情
    @Override
    public SRS info(${r"Map<String, Object> param"}) {
        Wrapper${r"<Object>"} wrapper = new Wrapper<>();
        wrapper.eq("id", param.getOrDefault("id", 0));
        DbEnt DbEnt = dao.selectOne("${table.name}", wrapper);
        return SRS.bySuccess(DbEnt);
    }

    //查询集合
    @Override
    public SRS list(${r"Map<String, Object> param"}) {
        Wrapper${r"<Object>"} wrapper = new Wrapper<>();
        wrapper.eq("id", param.getOrDefault("id", 0));
        List${r"<DbEnt>"} list = dao.list("${table.name}", wrapper);
        return SRS.bySuccess(list);
    }

    //分页查询
    @Override
    public SRS page(${r"Map<String, Object> param"}) {
        Wrapper${r"<Object>"} wrapper = new Wrapper<>();
        wrapper.eq("id", param.getOrDefault("id", 0));
        DbPage${r"<DbEnt>"} page = dao.page("${table.name}", new DbPage<>(param), wrapper);
        return SRS.bySuccess(page);
    }
}
